//
//  BookViewController.m
//  shike
//
//  Created by RegentSoft on 2017/4/20.
//  Copyright © 2017年 RegentSoft. All rights reserved.

//书本
#import "BookViewController.h"
#import "BookTableViewCell.h"
#import "BookDetailsViewController.h"
@interface BookViewController ()<UITableViewDelegate,UITableViewDataSource>{
    
}
@property(nonatomic,strong)UITableView *foundTabView;
@property(nonatomic,strong)NSMutableArray *modelArray;
@end
@implementation BookViewController
-(void)viewWillAppear:(BOOL)animated{
    _modelArray = [[NSMutableArray alloc] init];
    [self httpRequest];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    //导航栏的标题颜色字体
    self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
    self.navigationController.navigationBar.tintColor = [UIColor colorWithHexString:@"#999999"];
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName :[UIColor colorWithHexString:@"#323232"],NSFontAttributeName :[UIFont systemFontOfSize:16.0]}];
    self.title = @"书本名称";
    self.view.backgroundColor = [UIColor colorWithHexString:@"#F0F0F5"];
    _foundTabView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height-44) style:UITableViewStylePlain];
    _foundTabView.delegate = self;
    _foundTabView.dataSource = self;
    [self.view addSubview:_foundTabView];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _modelArray.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString * cellIdenifer =@"cellIdenifer";
    BookTableViewCell * cell =[tableView dequeueReusableCellWithIdentifier:cellIdenifer];
    if (!cell) {
        cell =[[BookTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdenifer];
    }
    NSDictionary * dic = [_modelArray objectAtIndex:indexPath.row];
    NSArray * array = [NSArray arrayWithObjects:@"book",@"graphic",@"PDF",@"video",@"book",@"book",@"book",nil];
    if (_modelArray.count>0) {
        cell.titleLabel.text = [NSString stringWithFormat:@"%@",[dic objectForKey:@"name"]];
        cell.contentLabel.text = @"d8dd8";
        cell.headImage.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@",[array objectAtIndex:indexPath.row]]];

    }
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    BookDetailsViewController * detailsView =[[BookDetailsViewController alloc] init];
    detailsView.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:detailsView animated:YES];
    
}
-(void)httpRequest{
    [self loadProgressViewIsShow:YES];
    NSString * urlString =@"http://120.77.252.204/api/module/list?tenantId=d8dd8152143711e7a393a45e60ce3abd&status=1";
    [[RSNetworkManager sharedManager] GET:urlString parameters:nil progress:^(NSProgress * _Nonnull uploadProgress) {
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary * dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil];
        NSLog(@"1111====%@",dic);
        NSDictionary * dataDic = [dic objectForKey:@"data"];
        if ([dataDic allKeys].count>0) {
            _modelArray = [dataDic objectForKey:@"module_list"];
            [_foundTabView reloadData];
        }
        [self loadProgressViewIsShow:NO];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        [self showLoadProgressViewWithMessage:error.localizedDescription delay:2.0];
        [self loadProgressViewIsShow:NO];
    }];
}


@end
